package cn.edu.cug.cs.gtl.renders.openinventor.meshes;

import cn.edu.cug.cs.gtl.apis.render.basics.Box3f;
import cn.edu.cug.cs.gtl.apis.render.meshes.Cell;
import cn.edu.cug.cs.gtl.apis.render.meshes.CoordinatesInfo;
import cn.edu.cug.cs.gtl.apis.render.meshes.Mesh;
import cn.edu.cug.cs.gtl.renders.openinventor.basics.Box3fImpl;
import com.openinventor.meshviz.data.PbMesh;

public class MeshImpl implements Mesh {
    private PbMesh nativeObject = null;
    public MeshImpl(PbMesh v){
        this.nativeObject = v;
    }
    @Override
    public Object getNativeObject() {
        return nativeObject;
    }

    @Override
    public boolean attach(Object nativeObject) {
        if(nativeObject instanceof  PbMesh){
            this.nativeObject = (PbMesh) nativeObject;
            return true;
        }
        return false;
    }

    @Override
    public Object detach() {
        Object r = this.nativeObject;
        this.nativeObject=null;
        return r;
    }

    @Override
    public Box3f getBoundingBox() {
        return new Box3fImpl(nativeObject.getBoundingBox());
    }

    @Override
    public Cell getCell(int cellIndex) {
        return new CellImpl(nativeObject.getCell(cellIndex));
    }

    @Override
    public CoordinatesInfo getCoordinates() {
        return new CoordinatesInfoImpl(nativeObject.getCoordinates());
    }

    @Override
    public void setCoordinates(float[] xs, float[] ys, float[] zs) {
        nativeObject.setCoordinates(xs,ys,zs);
    }

    @Override
    public int getNumberOfCells() {
        return nativeObject.getNumCells();
    }

    @Override
    public int getNumberOfNodes() {
        return nativeObject.getNumNodes();
    }

    @Override
    public float getVolume() {
        return nativeObject.getVolume();
    }

    /**
     * Gets the area of the mesh.
     *
     * @return
     */
    @Override
    public float getArea() {
        return nativeObject.getArea();
    }
}
